﻿using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Mvc;
using Common;

namespace YaoYunDong.Controllers
{
    public class PublicController : Controller
    {
        public FileContentResult LoginValidateImage()
        {
            var vn = new ValidateNumber();
            string s = vn.CreateValidateNumber(4);
            Session["ValidateNumber"] = s;
            MemoryStream img = vn.CreateValidateGraphic(s, 60, 24, 14, 3, 3);
            return File(img.GetBuffer(), "image/JPEG");
        }

        public string TempUpload()
        {
            HttpPostedFile file = System.Web.HttpContext.Current.Request.Files["FileData"];
            string uploadpath = System.Web.HttpContext.Current.Server.MapPath("~/TempImage/");

            if (file != null)
            {
                if (!Directory.Exists(uploadpath))
                {
                    Directory.CreateDirectory(uploadpath);
                }
                file.SaveAs(uploadpath + file.FileName);
                return uploadpath + file.FileName;
            }
            return "0";
        }

        public ActionResult DropDown(Dictionary<string, string> options, string key)
        {
            ViewData["Options"] = options;
            ViewData["Key"] = key;
            return View("~/Views/Shared/DropDown.ascx");
        }
    }
}